package com.wechatapp.mengyao.poetry.service.impl;

import com.wechatapp.mengyao.poetry.entity.ChinesePoetryReciteFile;
import com.wechatapp.mengyao.poetry.mapper.ChinesePoetryReciteFileMapper;
import com.wechatapp.mengyao.poetry.service.ChinesePoetryReciteFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author yanghuaxu
 * @date 2025/6/7 21:07
 */
@Service
public class ChinesePoetryReciteFileServiceImpl implements ChinesePoetryReciteFileService {

    @Autowired
    private ChinesePoetryReciteFileMapper chinesePoetryReciteFileMapper;

    @Override
    public String getFilePathById(Long poetryId) {
        List<ChinesePoetryReciteFile> fileList = chinesePoetryReciteFileMapper.getPoetryFileById(poetryId, ChinesePoetryReciteFile.Type.GUSHIWEN.getType());
        if (CollectionUtils.isEmpty(fileList)) {
            fileList = chinesePoetryReciteFileMapper.getPoetryFileById(poetryId, ChinesePoetryReciteFile.Type.TTS.getType());
        }
        if (fileList.size() > 0) {
            return fileList.get(0).getFilePath();
        } else {
            return null;
        }
    }
}
